package com.sport.controller;

import com.sport.model.PageParams;
import com.sport.model.Result;
import com.sport.entity.Productlabeling;
import com.sport.service.ProductlabelingService;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;

/**
 * 烟的详情信息;(productlabeling)表控制层
 * @author: 开心摆烂
 * @date : 2024-12-24
 */
@RestController
@Tag(name = "烟的详情信息")
@RequestMapping("/productlabeling")
@ApiSupport(author = "开心摆烂", order = 9)
public class ProductlabelingController {

    @Resource
    private ProductlabelingService productlabelingService;

    @PostMapping("/page")
    @ApiOperationSupport(order = 1)
    @Operation(summary = "分页查询")
    public Result<Page<Productlabeling>> pageQuery(@RequestBody PageParams<Productlabeling> pageParams) {
        // 1.查询参数
        Productlabeling params = pageParams.getParams();
        LambdaQueryWrapper<Productlabeling> lqw = new LambdaQueryWrapper<>();
        // 2.查询条件
        lqw.eq(params.getProductId() != null, Productlabeling::getProductId, params.getProductId());
        lqw.like(params.getProductname() != null, Productlabeling::getProductname, params.getProductname());
        // 3.分页查询
        return Result.success(productlabelingService.page(pageParams.getPage(), lqw));
    }

    @PostMapping("/insert")
    @ApiOperationSupport(order = 2)
    @Operation(summary = "新增数据")
    public Result<Boolean> insert(@RequestBody Productlabeling productlabeling) {
        if (productlabelingService.save(productlabeling)) {
            return Result.success();
        }
        return Result.error();
    }

    @PostMapping("/update")
    @ApiOperationSupport(order = 3)
    @Operation(summary = "更新数据")
    public Result<Boolean> update(@RequestBody Productlabeling productlabeling) {
        if (productlabelingService.updateById(productlabeling)) {
            return Result.success();
        }
        return Result.error();
    }

    @GetMapping("/delete/{id}")
    @ApiOperationSupport(order = 4)
    @Operation(summary = "通过主键删除数据", parameters = {
            @Parameter(name = "id", description = "主键", required = true, in = ParameterIn.PATH)
    })
    public Result<Boolean> deleteById(@PathVariable String id){
        if (productlabelingService.removeById(id)) {
            return Result.success();
        }
        return Result.error();
    }
}